from django.contrib.auth.models import Permission,Group
from django.contrib.contenttypes.models import ContentType
from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet
from meiduo_admin.my_paginate import MyPageNumberPagination
from . import permission_serializers

# 可以获取权限管理页面的数据
class PermissionViewSet(ModelViewSet):
    pagination_class = MyPageNumberPagination
    serializer_class = permission_serializers.PermissionSerializer
    queryset = Permission.objects.order_by("id").all()

# 可以获取新增权限的权限类型
class PermissionContentTypeView(ListAPIView):
    serializer_class = permission_serializers.PermissionContentTypeSerializer
    queryset = ContentType.objects.all()

# 可以获取用户组的数据
class GroupPermissionViewSet(ModelViewSet):
    pagination_class = MyPageNumberPagination
    serializer_class = permission_serializers.GroupPermissionSerializer
    queryset = Group.objects.all()

# 可以获取增加用户组页面的权限表数据
class PermissionSimpleView(ListAPIView):
    serializer_class = permission_serializers.PermissionSimpleSerializer
    queryset = Permission